// 动态计算服务端设计样式
export function ShowStyle(data: object, extra: object = {}, allow: any = ''): object {
	let width = 750, style = Object.assign({}, JSON.parse(JSON.stringify(data)), extra || {})
	let allows = allow ? ',' + allow + ',' : false
	let borders: any = { t: 'borderTopWidth', l: 'borderLeftWidth', r: 'borderRightWidth', b: 'borderBottomWidth' }
	for (let key in style) {
		if (allows && allows.indexOf(key) === -1) {
			delete style[key]
			continue
		}
		let value = style[key]
		let realpx = (isNaN(Number(value)) ? 0 : value * width / 100) + 'rpx'
		if (/^[_v]/.test(key)) delete style[key]
		if (key === 'vWidth2') {
			style.width = realpx
			style.maxWidth = '100%'
		}
		if (key === 'vWidth') style.width = value + '%'
		if (key === 'vHeight') style.height = realpx
		if (key === 'vFontSize') style.fontSize = realpx
		if (key === 'vLineHeight') style.lineHeight = realpx
		if (key === 'vMarginTop') style.marginTop = realpx
		if (key === 'vBorderRadius') {
			style.overflow = 'hidden'
			style.borderRadius = realpx
		}
		for (let i in borders) {
			if (key === 'vBorderType' && value) {
				value.indexOf(i) < 0 && (style[borders[i]] = 0)
			}
			if (key === 'vBorderWidth') {
				if (typeof style[borders[i]] === 'undefined') {
					style[borders[i]] = realpx
					style.boxSizing = 'border-box'
				}
			}
		}
		if (key === 'vBackgroundImage') {
			style.backgroundImage = "url('" + value + "')"
		}
		if (key === 'vPaddingTopBottom') {
			style.boxSizing = 'border-box'
			style.paddingTop = style.paddingBottom = realpx
		}
		if (key === 'vPaddingLeftRight') {
			style.boxSizing = 'border-box'
			style.paddingLeft = style.paddingRight = realpx
		}
		if (key === 'vMarginTopBottom') {
			style.boxSizing = 'border-box'
			style.marginTop = style.marginBottom = realpx
		}
		if (key === 'vMarginLeftRight') {
			style.boxSizing = 'border-box'
			style.marginLeft = style.marginRight = realpx
		}
		// '重复平铺','重复平铺','垂直平铺','全屏拉伸','居中裁减'
		if (key === 'vBackgroundType') {
			if (value === 0) {
				style.backgroundSize = 'auto'
				style.backgroundRepeat = 'repeat'
			} else if (value === 1) {
				style.backgroundSize = 'contain'
				style.backgroundRepeat = 'repeat no-repeat'
			} else if (value === 2) {
				style.backgroundSize = 'contain'
				style.backgroundRepeat = 'no-repeat repeat'
			} else if (value === 3) {
				style.backgroundSize = '100% 100%'
				style.backgroundRepeat = 'no-repeat'
			} else if (value === 4) {
				style.backgroundSize = 'cover'
				style.backgroundRepeat = 'no-repeat'
				style.backgroundPosition = 'center center'
			}
		}
	}
	return style
}